package org.hikari.qqbot.xiuxian.command;

import org.hikari.qqbot.xiuxian.command.logical.ShiLianCommand;
import org.hikari.qqbot.xiuxian.command.logical.TimesCommand;

import java.util.Date;

/**
 * created at 2024-12-10 22:17:38
 *
 * @author yinchao
 * @version 1.0
 **/
public interface ICommand {

    String getCommand();

    default Date getSendTime() {
        return null;
    }

    default Long getGroupId() {
        return null;
    }

    default Long getUserId() {
        return null;
    }

    default ICommand groupId(Long groupId) {
        throw new UnsupportedOperationException("command[" + getClass().getName() + "] '" + getCommand() + "' can't set chat group id");
    }

    default ICommand userId(Long userId) {
        throw new UnsupportedOperationException("command[" + getClass().getName() + "] '" + getCommand() + "' can't set chat user id");
    }

    default ICommand delay(Date date) {
        throw new UnsupportedOperationException("command[" + getClass().getName() + "] '" + getCommand() + "' can't delay");
    }

    default ICommand delay(Date date, long duration) {
        this.delay(new Date(date.getTime() + duration));
        return this;
    }

    default ICommand delay(long duration) {
        Date date = this.getSendTime() == null ? new Date() : this.getSendTime();
        return this.delay(date, duration);
    }

    default ICommand shiLian() {
        if (this instanceof ShiLianCommand) {
            return this;
        }
        return new ShiLianCommand(this instanceof AbstractLogicalCommand c ? c.delegate(true) : this);
    }

    default ICommand times(int times) {
        if (times <= 1) {
            return this;
        }
        return new TimesCommand(this instanceof AbstractLogicalCommand c ? c.delegate(true) : this, times);
    }

}
